package com.tianhui.consignortwofei.role;

import android.text.TextUtils;

import com.tianhui.consignortwofei.BuildConfig;
import com.tianhui.consignortwofei.constant.Role;
import com.tianhui.consignortwofei.manager.SharedPreferenceManager;
import com.tianhui.consignortwofei.mvp.model.enty.ProfileInfo;

/**
 * @author fgs
 * @date 2021/6/3
 * @description
 **/
public class RoleController implements IRole {
    IRole iRole;

    private RoleController() {
        iRole = new UnKnownRole();
    }

    public static RoleController getInstance() {
        return SingletonHolder.instance;
    }

    private static class SingletonHolder {
        private static final RoleController instance = new RoleController();
    }


    public void setRole(IRole iRole) {
        this.iRole = iRole;
    }

    public void setRole(ProfileInfo profile) {
        IRole iRole = new UnKnownRole();

        if (BuildConfig.FLAVOR.equals("officer")) {
            iRole = new OfficerRole();
            SharedPreferenceManager.getInstance().setRolePosition(1);
        } else {
            if (!TextUtils.isEmpty(profile.roleid)) {
                if (profile.roleid.equals(Role.MANAGER)) {//管理员
                    iRole = new ManagerRole();
                    SharedPreferenceManager.getInstance().setRolePosition(0);
                }
//                else if (profile.roleid.equals(Role.OFFICER) && BuildConfig.FLAVOR.equals("officer")) {//客服
//                    iRole = new OfficerRole();
//                    SharedPreferenceManager.getInstance().setRolePosition(1);
//                }
                else if (profile.roleid.equals(Role.PLATFORM)) {//平台用户
                    iRole = new PlatformRole(profile);
                    SharedPreferenceManager.getInstance().setRolePosition(4);
                } else if (profile.roleid.equals(Role.LOGISTICS)||profile.roleid.equals(Role.LOGISTICSTWO)) {//物流
                    iRole = new LogisticsRole(profile);
                    SharedPreferenceManager.getInstance().setRolePosition(3);
                } else if (profile.roleid.equals(Role.SALESMAN)||profile.roleid.equals(Role.MINISTER)) {//销售员
                    iRole = new SalesmanRole();
                    SharedPreferenceManager.getInstance().setRolePosition(2);
                }

            }
        }


        setRole(iRole);
    }

    @Override
    public void deliverGoodsOperate() {
        iRole.deliverGoodsOperate();
    }

    @Override
    public void dispatchOperate() {
        iRole.dispatchOperate();
    }

    @Override
    public void sourceOperate() {
        iRole.sourceOperate();
    }

    @Override
    public void freightOperate() {
        iRole.freightOperate();
    }

    @Override
    public void paymentOperate() {
        iRole.paymentOperate();
    }

    @Override
    public void manageSourceOperate() {
        iRole.manageSourceOperate();
    }

    @Override
    public boolean isShowOrderTypeTabLayout() {
        return iRole.isShowOrderTypeTabLayout();
    }

    @Override
    public boolean isShowCarrierManageView() {
        return iRole.isShowCarrierManageView();
    }

    @Override
    public boolean isShowStaticsView() {
        return iRole.isShowStaticsView();
    }

    @Override
    public boolean isCarrierEditable() {
        return iRole.isCarrierEditable();
    }

    @Override
    public boolean isShowBusinessView() {
        return iRole.isShowBusinessView();
    }

    @Override
    public boolean isShowCustomerName() {
        return iRole.isShowCustomerName();
    }

    @Override
    public boolean isShowPerfectData() {
        return iRole.isShowPerfectData();
    }

    @Override
    public boolean isShowSalesMan() {
        return iRole.isShowSalesMan();
    }

    @Override
    public boolean isNeedRequestAuditState() {
        return iRole.isNeedRequestAuditState();
    }

    @Override
    public boolean isCanTerminateDispatchOrder() {
        return iRole.isCanTerminateDispatchOrder();
    }

    @Override
    public boolean isDispatchOrderShowVehicleNumber() {
        return iRole.isDispatchOrderShowVehicleNumber();
    }

    @Override
    public boolean isShowEditImage() {
        return iRole.isShowEditImage();
    }

    @Override
    public boolean isShowBelongArea() {
        return iRole.isShowBelongArea();
    }
}
